package com.wc.alorithm_blue_bridge._前缀和与差分.Q3260;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/11/22 21:25
 * @description
 * 最大数组和
 * https://www.lanqiao.cn/problems/3260/learning/?page=1&first_category_id=1
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int t = scan.nextInt();
        while(t-- > 0){
            int n = scan.nextInt();
            int k = scan.nextInt();
            int[] array = new int[n + 1];
            // pre[i] 表示前i项的和
            long[] pre = new long[n + 1];
            for(int i = 1;i <= n; i++){
                array[i] = scan.nextInt();
            }
            Arrays.sort(array);
            for(int i = 1;i <= n;i++){
                pre[i] = pre[i - 1] + array[i];
            }
            long ans = -1;
            for(int i = 0; i <= k;i++){
                ans = Math.max(ans, pre[n - i] - pre[2 * (k - i)]);
            }
            System.out.println(ans);
        }
        scan.close();
    }
}
